<template>
	<van-address-list v-model="chosenAddressId" :list="list" default-tag-text="默认" @add="onAdd" @edit="onEdit" />
</template>

<script>
	import request, {
		getUrl
	} from "@/utils/request2";
	import showDlg from "@/utils/tools.js";
	import {
		removeStorageToken,
		getStorageUser,
		setStorageUser
	} from "@/utils/storage.js" //导入
	export default {
		data() {
			return {
				chosenAddressId: '1',
				list: [
				]
			}
		},
		created() {
			request({ //页面加载的时候 发起请求
				url: getUrl("User/getUserAddList"), //URL
				method: "get", //请求方法
				params: { //Post传data，get请求传params
					uid: getStorageUser().id
				}
			}).then(res => { //成功回调
				console.log(res.data.data)
				var st = JSON.stringify(res.data.data) //JSON转字符串
				st = st.replaceAll("uname", "name")
				st = st.replaceAll("addressid", "id")
				var obj = JSON.parse(st) //转回JSON
				this.list = obj
				for (var i = 0; i < this.list.length; i++) {
					if (this.list[i].isdef == 1) {
						this.list[i]["isDefault"] = true //向json对象中增加属性
					}
				}
			}).catch(res => { //失败回调

			})
		},
		methods: {
			onEdit(e) {
				this.$router.push("/addressedit?addressid=" + e.id)
			},
			onAdd() {
				this.$router.push("/addressadd")
			}
		}
	}
</script>

<style>
</style>
